﻿using System;
using System.ComponentModel;
using System.Text;
using System.Xml.Serialization;
using XCode;
using NewLife.Log;

namespace BingZi.HY.Core
{
 

    /// <summary>
    ///初始化数据
    /// </summary>
    public partial class sys_Module<TEntity>
    {
        #region 数据
        /// <summary>
        /// 首次连接数据库时初始化数据，仅用于实体类重载，用户不应该调用该方法
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        protected override void InitData()
        {

            base.InitData();

            if (Meta.Count > 0) return;

            if (XTrace.Debug) XTrace.WriteLine("开始初始化{0}模块管理数据……", typeof(TEntity).Name);



            Meta.BeginTrans();
            try
            {

                #region "初始化基础模组的数据"
                //初始化基础模组的数据
               sys_Applications sys_App = sys_Applications.Find(sys_Applications._.A_AppName, "基础模组");
               if (sys_App != null && sys_App.ApplicationID > 0)
               {
                   //创建基础模组下的顶级模块
                   TEntity entity = new TEntity();
                   entity.M_ApplicationID = sys_App.ApplicationID;
                   entity.M_ParentID = 0;
                   entity.M_PageCode = "S00";
                   entity.M_CName = "系统应用";
                   entity.M_OrderLevel = "0000";
                   entity.M_IsSystem = 1;
                   entity.M_Close = 0;
                   if (entity.Insert() > 0)
                   {
                       //创建顶级模块下的菜单
                       int ModuleID = entity.ModuleID;


                       // VALUES(2,1,1,'S00M00','应用列表管理','Module/FrameWork/SystemApp/AppManager/list.aspx','0001',1,0,'~/manager/images/icon/applist.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M00";
                       entity.M_CName = "应用列表管理";
                       entity.M_Directory = "Module/FrameWork/SystemApp/AppManager/list.aspx";
                       entity.M_OrderLevel = "0001";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/applist.gif";
                       entity.Insert();

                       // VALUES(4,1,1,'S00M01','部门资料管理','Module/FrameWork/SystemApp/GroupManager/Frame.aspx','0003',1,0,'~/manager/images/icon/grouplist.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M01";
                       entity.M_CName = "部门资料管理";
                       entity.M_Directory = "Module/FrameWork/SystemApp/GroupManager/Frame.aspx";
                       entity.M_OrderLevel = "0003";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/grouplist.gif";
                       entity.Insert();

                       // VALUES(5,1,1,'S00M02','角色资料管理','Module/FrameWork/SystemApp/RoleManager/RoleList.aspx','0004',1,0,'~/manager/images/icon/rule.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M02";
                       entity.M_CName = "角色资料管理";
                       entity.M_Directory = "Module/FrameWork/SystemApp/RoleManager/RoleList.aspx";
                       entity.M_OrderLevel = "0004";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/rule.gif";
                       entity.Insert();

                       // VALUES(6,1,1,'S00M03','用户资料管理','Module/FrameWork/SystemApp/UserManager/default.aspx','0005',1,0,'~/manager/images/icon/user.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M03";
                       entity.M_CName = "用户资料管理";
                       entity.M_Directory = "Module/FrameWork/SystemApp/UserManager/default.aspx";
                       entity.M_OrderLevel = "0005";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/user.gif";
                       entity.Insert();

 

                       // VALUES(7,1,1,'S00M04','应用字段设定','Module/FrameWork/SystemApp/FieldManager/default.aspx','0006',1,0,'~/manager/images/icon/FieldManager.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M04";
                       entity.M_CName = "应用字段设定";
                       entity.M_Directory = "Module/FrameWork/SystemApp/FieldManager/default.aspx";
                       entity.M_OrderLevel = "0007";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 1;
                       entity.M_Icon = "~/manager/images/icon/FieldManager.gif";
                       entity.Insert();

                       // VALUES(8,1,1,'S00M05','事件日志管理','Module/FrameWork/SystemApp/EventManager/default.aspx','0007',1,0,'~/manager/images/icon/log.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M05";
                       entity.M_CName = "事件日志管理";
                       entity.M_Directory = "Module/FrameWork/SystemApp/EventManager/default.aspx";
                       entity.M_OrderLevel = "0008";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/log.gif";
                       entity.Insert();

                       // VALUES(9,1,1,'S00M06','在线用户列表','Module/FrameWork/SystemApp/OnlineUserManager/default.aspx','0008',1,0,'~/manager/images/icon/online.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M06";
                       entity.M_CName = "在线用户列表";
                       entity.M_Directory = "Module/FrameWork/SystemApp/OnlineUserManager/default.aspx";
                       entity.M_OrderLevel = "0009";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/online.gif";
                       entity.Insert();

                       // VALUES(26,1,1,'S00M07','应用模块管理','Module/FrameWork/SystemApp/ModuleManager/list.aspx','0002',1,0,'~/manager/images/icon/module.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S00M07";
                       entity.M_CName = "应用模块管理";
                       entity.M_Directory = "Module/FrameWork/SystemApp/ModuleManager/list.aspx";
                       entity.M_OrderLevel = "0002";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/module.gif";
                       entity.Insert();
 
                   }

                   //创建基础模组下的顶级模块
                   entity = new TEntity();
                   entity.M_ApplicationID = sys_App.ApplicationID;
                   entity.M_ParentID = 0;
                   entity.M_PageCode = "S01";
                   entity.M_CName = "系统维护";
                   entity.M_OrderLevel = "0100";
                   entity.M_IsSystem = 1;
                   entity.M_Close = 0;
                   if (entity.Insert() > 0)
                   {
                       //创建顶级模块下的菜单
                       int ModuleID = entity.ModuleID;


                       // VALUES(28,1,27,'S01M00','系统运行状态','Module/FrameWork/SystemMaintenance/SystemState/default.aspx','0101',1,0,'~/manager/images/icon/status.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S01M00";
                       entity.M_CName = "系统运行状态";
                       entity.M_Directory = "Module/FrameWork/SystemMaintenance/SystemState/default.aspx";
                       entity.M_OrderLevel = "0101";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/status.gif";
                       entity.Insert();

                       // VALUES(29,1,27,'S01M01','系统出错日志','Module/FrameWork/SystemMaintenance/SystemErrorLog/default.aspx','0102',1,0,'~/manager/images/icon/bug.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S01M01";
                       entity.M_CName = "系统出错日志";
                       entity.M_Directory = "Module/FrameWork/SystemMaintenance/SystemErrorLog/default.aspx";
                       entity.M_OrderLevel = "0102";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/bug.gif";
                       entity.Insert();

                       // VALUES(30,1,27,'S01M02','系统环境配置','Module/FrameWork/SystemMaintenance/SystemConfig/default.aspx','0103',1,0,'~/manager/images/icon/config.gif')
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "S01M02";
                       entity.M_CName = "系统环境配置";
                       entity.M_Directory = "Module/FrameWork/SystemMaintenance/SystemConfig/default.aspx";
                       entity.M_OrderLevel = "0103";
                       entity.M_IsSystem = 1;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/config.gif";
                       entity.Insert();

                   }
               }
                #endregion


               #region "初始化应用模组的数据"
               //初始化基础模组的数据
               sys_App = sys_Applications.Find(sys_Applications._.A_AppName, "扩展应用");
               if (sys_App != null && sys_App.ApplicationID > 0)
               {


                   TEntity entity = new TEntity();
                   entity.M_ApplicationID = sys_App.ApplicationID;
                   entity.M_ParentID = 0;
                   entity.M_PageCode = "K01";
                   entity.M_CName = "基础数据维护";
                   entity.M_OrderLevel = "0000";
                   entity.M_IsSystem = 0;
                   entity.M_Close = 0;
                   if (entity.Insert() > 0)
                   {
                       //创建顶级模块下的菜单
                       int ModuleID = entity.ModuleID;

                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "K01M01";
                       entity.M_CName = "分类数据管理";
                       entity.M_Directory = "Module/admin/app_CategoryManager/Frame.aspx";
                       entity.M_OrderLevel = "0001";
                       entity.M_IsSystem = 0;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/module.gif";
                       entity.Insert();
  

                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "K01M02";
                       entity.M_CName = "HTML模块维护";
                       entity.M_Directory = "Module/admin/app_Help/Frame.aspx";
                       entity.M_OrderLevel = "0002";
                       entity.M_IsSystem = 0;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/applist.gif";
                       entity.Insert();

                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "K01M03";
                       entity.M_CName = "商品数据维护";
                       entity.M_Directory = "Module/admin/app_Product/Default.aspx";
                       entity.M_OrderLevel = "0003";
                       entity.M_IsSystem = 0;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/applist.gif";
                       entity.Insert();


                   }



                   //创建基础模组下的顶级模块
                   entity = new TEntity();
                   entity.M_ApplicationID = sys_App.ApplicationID;
                   entity.M_ParentID = 0;
                   entity.M_PageCode = "K00";
                   entity.M_CName = "会员与订单数据";
                   entity.M_OrderLevel = "0000";
                   entity.M_IsSystem = 1;
                   entity.M_Close = 0;
                   if (entity.Insert() > 0)
                   {
                       //创建顶级模块下的菜单
                       int ModuleID = entity.ModuleID;
 
                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "K00M01";
                       entity.M_CName = "会员数据管理";
                       entity.M_Directory = "Module/admin/UserManager/Default.aspx";
                       entity.M_OrderLevel = "0001";
                       entity.M_IsSystem = 0;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/user.gif";
                       entity.Insert();


                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "K00M02";
                       entity.M_CName = "订单数据管理";
                       entity.M_Directory = "Module/admin/app_Order/Default.aspx";
                       entity.M_OrderLevel = "0002";
                       entity.M_IsSystem = 0;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/applist.gif";
                       entity.Insert();


                       entity = new TEntity();
                       entity.M_ApplicationID = sys_App.ApplicationID;
                       entity.M_ParentID = ModuleID;
                       entity.M_PageCode = "K00M03";
                       entity.M_CName = "评论数据管理";
                       entity.M_Directory = "Module/admin/app_Comment/Default.aspx";
                       entity.M_OrderLevel = "0003";
                       entity.M_IsSystem = 0;
                       entity.M_Close = 0;
                       entity.M_Icon = "~/manager/images/icon/applist.gif";
                       entity.Insert();

                     
 
                   }



             




               }
               #endregion
 



  

                Meta.Commit();
            }
            catch(Exception ex) {
                if (XTrace.Debug) XTrace.WriteLine("初始化{0}模块管理数据失败,具体原因:{1}", typeof(TEntity).Name, ex.Message);
                Meta.Rollback(); throw; }

            if (XTrace.Debug) XTrace.WriteLine("完成初始化{0}模块管理数据！", typeof(TEntity).Name);
        }
        #endregion
    }
}
